<template>
    <view class="uploadimag" @tap="addImag">
            <image :src="imagUrl" class="upimag" v-if="imagUrl" />
            <image src="/static/images/upimag_bg.png" class="bg" v-else />
            
    </view>
</template>
<script>

import {postUpLoadFile} from '@/request/actions';

export default {
        props:{
        
            cb:{
                type:String,
                default:'getImag'
            }
        },
        data(){
            return{
                 imagUrl:''
            }
           
        },
        methods:{
                addImag(){
                    let type = this.upLoadType;
                    let method = this.method;

                    wx.chooseImage({
                        count:1,
                        sizeType:'compressed',
                        success: res => {
                            
                                if(res.errMsg == "chooseImage:ok"){
                                    
                                    let path = res.tempFilePaths[0]

                                            postUpLoadFile(path).then(r=>{
                                           
                                                    let {data:res} = r;
                                                    res = JSON.parse(res);
                                                    
                                                    if(res.status == 200){
                                                        
                                                        this.imagUrl = res.data;
                                                      
                                                        this.$emit('setImag',this.imagUrl);

                                                    }
                                                    
                                                
                                                 
                                                })

                               
                                }



                              }

                          
                        })
                }
        }
      
}
</script>
<style lang="scss">
    .uploadimag{
        position: relative;
        width: 144rpx;
        height: 144rpx;
        position: relative;
        z-index: 1;

        .bg{
            position: absolute;
            top:0;
            left:0;
            width: 144rpx;
            height: 144rpx;
            z-index: 1;

        }
        .upimag{
            position: absolute;
            top:0;
            left:0;
            width: 144rpx;
            height: 144rpx;
            z-index: 2;
        }
    }
</style>
